package com.hp.attendance.serlvet.overtime;

import com.hp.attendance.entity.PageInfo;
import com.hp.attendance.entity.dto.DepOvertimeDto;
import com.hp.attendance.service.OvertimeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/overtimeList")
public class OvertimeListServlet extends HttpServlet {
    private OvertimeService overtimeService=new OvertimeService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //分页查询

        try {
            String pageNo = req.getParameter("pageNo");
            if(pageNo==null ||"".equals(pageNo.trim())){
                pageNo="1";
            }
            PageInfo<DepOvertimeDto> page = overtimeService.getPage(Integer.parseInt(pageNo), 10);
            req.setAttribute("page",page);
            req.getRequestDispatcher("/pages/overtime_list.jsp").forward(req, resp);
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

    }




    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
